import * as echarts from 'echarts/core'
import {
  LineChart,
  BarChart
} from 'echarts/charts'
import {
  TitleComponent,
  TooltipComponent,
  GridComponent,
  LegendComponent
} from 'echarts/components'
import {
  CanvasRenderer
} from 'echarts/renderers'

// 注册必须的组件
echarts.use([
  TitleComponent,
  TooltipComponent,
  GridComponent,
  LegendComponent,
  LineChart,
  BarChart,
  CanvasRenderer
])

// 创建体重趋势图表
export function createWeightChart(el, data) {
  const chart = echarts.init(el)
  const option = {
    title: {
      text: '体重变化趋势'
    },
    tooltip: {
      trigger: 'axis'
    },
    xAxis: {
      type: 'category',
      data: data.dates
    },
    yAxis: {
      type: 'value',
      name: '体重(kg)'
    },
    series: [{
      data: data.weights,
      type: 'line',
      smooth: true
    }]
  }
  chart.setOption(option)
  return chart
}

// 创建血压趋势图表
export function createBPChart(el, data) {
  const chart = echarts.init(el)
  const option = {
    title: {
      text: '血压变化趋势'
    },
    tooltip: {
      trigger: 'axis'
    },
    legend: {
      data: ['收缩压', '舒张压']
    },
    xAxis: {
      type: 'category',
      data: data.dates
    },
    yAxis: {
      type: 'value',
      name: 'mmHg'
    },
    series: [
      {
        name: '收缩压',
        type: 'line',
        data: data.systolic,
        smooth: true
      },
      {
        name: '舒张压',
        type: 'line',
        data: data.diastolic,
        smooth: true
      }
    ]
  }
  chart.setOption(option)
  return chart
} 